package gui.swing.jTable;

import java.awt.Color;
import java.awt.Component;

import javax.swing.JTable;
import javax.swing.table.DefaultTableCellRenderer;

public class ZebraTableCellRenderer extends DefaultTableCellRenderer
{
    public Component getTableCellRendererComponent(JTable table, Object value,
            boolean isSelected, boolean hasFocus, int row, int column)
    {
        Component component = (Component) super.getTableCellRendererComponent(table, value, isSelected, hasFocus, row, column);
        if (isSelected)
        {
            component.setBackground(Color.blue);
            component.setForeground(Color.white);
        }
        else if(row%2 == 0)
        {
            component.setBackground(new Color(230,230,255));
            component.setForeground(Color.black);
        }
        else
        {
            component.setBackground(Color.white);
            component.setForeground(Color.black);
        }
        return this;
    }
}
